<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action {
	
	//#########index
    public function index(){
    	header("Content-Type:text/html; charset=utf-8");
    	$qybscst=D('Qybscst');$type=D('Type');
        $arr_qybscsto=$qybscst->getqybscsto();$qybscsto=$arr_qybscsto['data'];
        $this->assign('qybscsto',$qybscsto);

        //获取所有的type类型，比如企业QQ啥的
        $arr_typels=$type->getmlsorderbymoneydesc();$typels=$arr_typels['data'];
        $typelsnw=array();
        foreach($typels as $typev){
            $typev['typenm']=$typev['typenm'].'(￥'.$typev['typemoney'].')';
            array_push($typelsnw, $typev);
        }
        $this->assign('typels',$typelsnw);

    	$this->display('getnopw');

	}

	public function dogetnopw(){
    	header("Content-Type:text/html; charset=utf-8");
    	$dtup=D('Dtup');$alipay=D('Alipay');$type=D('Type');

        $typeid=$_GET['typeid'];
    	$alipayno=$_GET['alipayno'];
    	$qqno=$_GET['qqno'];

    	//先判断alipayno是否存在，这里需要一个大接口，假设先存在
    	$arr_alipayo=$alipay->getmobyalipayno($alipayno);$alipayo=$arr_alipayo['data'];
        if($alipayo){
            //然后判断是否已经取过,没有取过的需要给上交易码和QQ信息
            $arr_dtupo=$dtup->getmobyalipayno($alipayno);$dtupo=$arr_dtupo['data'];
            if(!$dtupo){
                //金额是否一致
                $arr_typeo=$type->getmo($typeid);$typeo=$arr_typeo['data'];
                if($typeo['typemoney']==$alipayo['alipaymoney']){
                    //从数据库里修改数据，并提取出来给用户
                    $arr_dt=$dtup->getnopw($typeid,$alipayno,$qqno);$dt=$arr_dt['data'];
                    $rslt_alipayno=$dt['rslt'];//0表示已经没有QQ企业号了 1表示有QQ企业号并给出数据
                    if($rslt_alipayno==1){
                        $data['dtupo']=$dt['dtupo'];
                    }
                }else{
                    $data['yjmoney']=$typeo['typemoney'];$data['sjmoney']=$alipayo['alipaymoney'];
                    $rslt_alipayno=4;
                }
                
                
                
            }else{$rslt_alipayno=3;}//已经提取过了
        }else{$rslt_alipayno=2;}//木有交易单号

    	

    	$data['rslt']=$rslt_alipayno;
        $data['typenm']=$typeo['typenm'];
    	
    	$this->ajaxReturn($data,'json');

	}

    public function dogetnopwbyalipaynoandqqno(){
        header("Content-Type:text/html; charset=utf-8");
        $dtup=D('Dtup');

        $alipayno=$_GET['alipayno'];
        $qqno=$_GET['qqno'];
        
        
        $arr_dt=$dtup->getnopwbyalipaynoandqqno($alipayno,$qqno);$dt=$arr_dt['data'];
        
        $rslt=$dt['rslt'];

        if($rslt==1){$dtupo=$dt['dtupo'];$data['dtupo']=$dtupo;}
        

        $data['rslt']=$rslt;

        
        $this->ajaxReturn($data,'json');

    }
}